﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Entities = Sita.Entities;

namespace Sita.Presentation.Code
{
    public class SessionModelManager
    {
        //public static IList<Entities.Group> GetSessionGroups(IList<Models.UserSessionGroup> groups)
        //{
        //    List<Entities.Group> ReturnList;

        //    ReturnList = new List<Entities.Group>();

        //    foreach (var CurrentGroup in groups)
        //    {
        //        ReturnList.Add(Code.SessionModelManager.GetSessionGroup(CurrentGroup));
        //    }
        //    return ReturnList;
        //}

        //public static IList<Models.UserSessionGroup> GetSessionGroups(IList<Entities.Group> groups)
        //{
        //    List<Models.UserSessionGroup> ReturnList;

        //    ReturnList = new List<Models.UserSessionGroup>();

        //    foreach (var CurrentGroup in groups)
        //    {
        //        ReturnList.Add(Code.SessionModelManager.GetSessionGroup(CurrentGroup));                
        //    }
        //    return ReturnList;
        //}

        //public static Entities.Group GetSessionGroup(Models.UserSessionGroup group)
        //{
        //    Entities.Group ReturnData;

        //    ReturnData = new Entities.Group();
        //    ReturnData.Code = group.Code;
        //    ReturnData.Name = group.Name;
        //    ReturnData.GroupID = group.GroupID;            

        //    foreach (var CurrentModule in group.Modules)
        //    {
        //        ReturnData.Modules.Add(Code.SessionModelManager.GetSessionModule(CurrentModule));
        //    }

        //    return ReturnData;
        //}

        //public static Models.UserSessionGroup GetSessionGroup(Entities.Group group)
        //{
        //    Models.UserSessionGroup ReturnData;

        //    ReturnData = new Models.UserSessionGroup();
        //    ReturnData.Code = group.Code;
        //    ReturnData.Name = group.Name;
        //    ReturnData.GroupID = group.GroupID;
        //    ReturnData.LocalizedName = group.LocalizedName;

        //    foreach (var CurrentModule in group.Modules)
        //    {
        //        ReturnData.Modules.Add(Code.SessionModelManager.GetSessionModule(CurrentModule));
        //    }

        //    return ReturnData;
        //}


        public static IList<Entities.Module> GetSessionModules(IList<Models.UserSessionModule> modules)
        {
            List<Entities.Module> ReturnList;

            ReturnList = new List<Entities.Module>();

            foreach (var CurrentModule in modules)
            {
                ReturnList.Add(Code.SessionModelManager.GetSessionModule(CurrentModule));
            }
            return ReturnList;
        }

        public static IList<Models.UserSessionModule> GetSessionModules(IList<Entities.Module> modules)
        {
            List<Models.UserSessionModule> ReturnList;

            ReturnList = new List<Models.UserSessionModule>();

            foreach (var CurrentModule in modules)
            {
                ReturnList.Add(Code.SessionModelManager.GetSessionModule(CurrentModule));
            }
            return ReturnList;
        }

        public static Entities.Module GetSessionModule(Models.UserSessionModule module)
        {
            Entities.Module ReturnData;

            ReturnData = new Entities.Module();
            ReturnData.Code = module.Code;
            ReturnData.Name = module.Name;
            ReturnData.ModuleID = module.ModuleID;
            //ReturnData.GroupID = module.GroupID;
            ReturnData.TargetAction = module.TargetAction;
            ReturnData.TargetController = module.TargetController;

            foreach (var CurrentBusiness in module.ModuleBusinesses)
            {
                ReturnData.ModuleBusinesses.Add(new Entities.ModuleBusiness()
                {
                    BusinessID = CurrentBusiness.BusinessID,
                    ModuleID = ReturnData.ModuleID
                });
            }

            return ReturnData;
        }

        public static Models.UserSessionModule GetSessionModule(Entities.Module module)
        {
            Models.UserSessionModule ReturnData;

            ReturnData = new Models.UserSessionModule();
            ReturnData.Code = module.Code;
            ReturnData.Name = module.Name;
            ReturnData.ModuleID = module.ModuleID;
            //ReturnData.GroupID = module.GroupID;
            ReturnData.TargetAction = module.TargetAction;
            ReturnData.TargetController = module.TargetController;
            ReturnData.LocalizedName = module.LocalizedName;

            //los business son los 4 q no uso
            //foreach (var CurrentBusiness in module.ModuleBusinesses)
            //{
            //    ReturnData.ModuleBusinesses.Add(new Models.UserSessionBusiness()
            //    {
            //        BusinessID = CurrentBusiness.BusinessID,
            //        Code = CurrentBusiness.Business.Code,
            //        LocalizedName = CurrentBusiness.Business.LocalizedName
            //    });
            //}


            return ReturnData;
        }

        public static IList<Entities.User> GetSessionUsers(IList<Models.UserSessionUser> users)
        {
            List<Entities.User> ReturnList;

            ReturnList = new List<Entities.User>();

            foreach (var CurrentUser in users)
            {
                ReturnList.Add(Code.SessionModelManager.GetSessionUser(CurrentUser));
            }
            return ReturnList;
        }

        public static IList<Models.UserSessionUser> GetSessionUsers(IList<Entities.User> users)
        {
            List<Models.UserSessionUser> ReturnList;

            ReturnList = new List<Models.UserSessionUser>();

            foreach (var CurrentUser in users)
            {
                ReturnList.Add(Code.SessionModelManager.GetSessionUser(CurrentUser));
            }
            return ReturnList;
        }

        public static Entities.User GetSessionUser(Models.UserSessionUser user)
        {
            Entities.User ReturnData;

            ReturnData = new Entities.User();
            ReturnData.Firstname = user.Firstname;
            ReturnData.Culture = user.Culture;
            ReturnData.DaylightSavingTime = user.DaylightSavingTime;
            ReturnData.Lastname = user.Lastname;
            ReturnData.Password = user.Password;
            //ReturnData.Theme = user.Theme;
            ReturnData.TimeZone = user.TimeZone;
            ReturnData.UserID = user.UserID;
            ReturnData.Username = user.Username;

            return ReturnData;
        }

        public static Models.UserSessionUser GetSessionUser(Entities.User user)
        {
            Models.UserSessionUser ReturnData;

            ReturnData = new Models.UserSessionUser();
            ReturnData.Firstname = user.Firstname;
            ReturnData.Culture = user.Culture;
            ReturnData.DaylightSavingTime = user.DaylightSavingTime;
            ReturnData.Lastname = user.Lastname;
            ReturnData.Password = user.Password;
            //ReturnData.Theme = user.Theme;
            ReturnData.TimeZone = user.TimeZone;
            ReturnData.UserID = user.UserID;
            ReturnData.Username = user.Username;
            ReturnData.FullName = user.FullName;

            return ReturnData;
        }

        public static IList<Entities.BusinessUnit> GetSessionBusinessUnits(IList<Models.UserSessionBusinessUnit> bus)
        {
            List<Entities.BusinessUnit> ReturnList;

            ReturnList = new List<Entities.BusinessUnit>();

            foreach (var CurrentBU in bus)
            {
                ReturnList.Add(Code.SessionModelManager.GetSessionBusinessUnit(CurrentBU));
            }
            return ReturnList;
        }

        public static IList<Models.UserSessionBusinessUnit> GetSessionBusinessUnits(IList<Entities.BusinessUnit> bus)
        {
            List<Models.UserSessionBusinessUnit> ReturnList;

            ReturnList = new List<Models.UserSessionBusinessUnit>();

            foreach (var CurrentBU in bus)
            {
                ReturnList.Add(Code.SessionModelManager.GetSessionBusinessUnit(CurrentBU));
            }
            return ReturnList;
        }

        public static Entities.BusinessUnit GetSessionBusinessUnit(Models.UserSessionBusinessUnit bu)
        {
            Entities.BusinessUnit ReturnData;

            ReturnData = new Entities.BusinessUnit();
            ReturnData.BusinessUnitID = bu.BusinessUnitID;
            //ReturnData.Culture = bu.Culture;
            ReturnData.Name = bu.Name;
            //ReturnData.OldBranchID = bu.OldBranchID;
            //ReturnData.TimeZone = bu.TimeZone;
            //ReturnData.Role = bu.Role;
            ReturnData.DollarPrice = bu.DollarPrice;
            ReturnData.PoundPrice = bu.PoundPrice;
            ReturnData.ImportPrice = bu.ImportPrice;

            foreach (var CurrentBU in bu.BusinessUnits1)
            {
                ReturnData.BusinessUnits1.Add(Code.SessionModelManager.GetSessionBusinessUnit(CurrentBU));
            }

            return ReturnData;
        }

        public static Models.UserSessionBusinessUnit GetSessionBusinessUnit(Entities.BusinessUnit bu)
        {
            Models.UserSessionBusinessUnit ReturnData;

            ReturnData = new Models.UserSessionBusinessUnit();
            ReturnData.BusinessUnitID = bu.BusinessUnitID;
            //ReturnData.Culture = bu.Culture;
            ReturnData.Name = bu.Name;
            //ReturnData.OldBranchID = bu.OldBranchID;
            //ReturnData.TimeZone = bu.TimeZone;
            ReturnData.Deleted = bu.Deleted;
            //ReturnData.Role = bu.Role;
            ReturnData.DollarPrice = bu.DollarPrice??0;
            ReturnData.PoundPrice = bu.PoundPrice ?? 0;
            ReturnData.ImportPrice = bu.ImportPrice ?? 0;

            foreach (var CurrentBU in bu.BusinessUnits1)
            {
                ReturnData.BusinessUnits1.Add(Code.SessionModelManager.GetSessionBusinessUnit(CurrentBU));
            }

            return ReturnData;
        }

        //public static IList<Entities.Business> GetSessionBusinesses(IList<Models.UserSessionBusiness> businesses)
        //{
        //    List<Entities.Business> ReturnList;

        //    ReturnList = new List<Entities.Business>();

        //    foreach (var CurrentBusiness in businesses)
        //    {
        //        ReturnList.Add(Code.SessionModelManager.GetSessionBusiness(CurrentBusiness));
        //    }
        //    return ReturnList;
        //}

        //public static IList<Models.UserSessionBusiness> GetSessionBusinesses(IList<Entities.Business> businesses)
        //{
        //    List<Models.UserSessionBusiness> ReturnList;

        //    ReturnList = new List<Models.UserSessionBusiness>();

        //    foreach (var CurrentBusiness in businesses)
        //    {
        //        ReturnList.Add(Code.SessionModelManager.GetSessionBusiness(CurrentBusiness));
        //    }
        //    return ReturnList;
        //}

        //public static Entities.Business GetSessionBusiness(Models.UserSessionBusiness business)
        //{
        //    Entities.Business ReturnData;

        //    ReturnData = new Entities.Business();            
        //    ReturnData.BusinessID = business.BusinessID;
        //    ReturnData.Code = business.Code;
        //    return ReturnData;
        //}

        //public static Models.UserSessionBusiness GetSessionBusiness(Entities.Business business)
        //{
        //    Models.UserSessionBusiness ReturnData;

        //    ReturnData = new Models.UserSessionBusiness();
        //    ReturnData.BusinessID = business.BusinessID;
        //    ReturnData.Code = business.Code;
        //    ReturnData.LocalizedName = business.LocalizedName;
        //    return ReturnData;
        //}

        public static IList<Entities.Permission> GetSessionPermissions(IList<Models.UserSessionPermission> permissions)
        {
            List<Entities.Permission> ReturnList;

            ReturnList = new List<Entities.Permission>();

            foreach (var CurrentPermission in permissions)
            {
                ReturnList.Add(Code.SessionModelManager.GetSessionPermission(CurrentPermission));
            }
            return ReturnList;
        }

        public static IList<Models.UserSessionPermission> GetSessionPermissions(IList<Entities.Permission> permissions)
        {
            List<Models.UserSessionPermission> ReturnList = new List<Models.UserSessionPermission>();

            foreach (var CurrentPermission in permissions)
            {
                ReturnList.Add(Code.SessionModelManager.GetSessionPermission(CurrentPermission));
            }
            return ReturnList;
        }

        public static Entities.Permission GetSessionPermission(Models.UserSessionPermission permission)
        {
            Entities.Permission ReturnData;

            ReturnData = new Entities.Permission();
            ReturnData.Code = permission.Code;

            return ReturnData;
        }

        public static Models.UserSessionPermission GetSessionPermission(Entities.Permission permission)
        {
            Models.UserSessionPermission ReturnData;

            ReturnData = new Models.UserSessionPermission();
            ReturnData.Code = permission.Code;

            return ReturnData;
        }
    }
}